#ifndef __MAINWIDGET_H__
#define __MAINWIDGET_H__

#include <QWidget>
#include <QMap>
#include <QString>

#include <common/status.h>

class QComboBox;
class QPushButton;
class QVBoxLayout;
class QHBoxLayout;
class QTimer;

class Friend;
class Chat;

namespace Client{
	class Client;
}

namespace Ui {

class FriendsList;
class ChatWindow;

class MainWidget: public QWidget{
Q_OBJECT

public:
	MainWidget(quint16 inactivityTime, QWidget *parent = 0);
	Friend *getMe();
	void setMe(Friend *me);
	void setInactivityTime(quint16 inactivityTime);

signals:
	void inviteFriend(const QString& _login);
	void removeFriend(Friend* _friend);
	void statusChanged(Status);
	void startChat(int id);
	void quitChat(Chat *chat);
	void inviteChat(Chat* chat, int friendId);
	void newOutcomingMessage(const QString &message, Chat *chat);
	void acceptInvitation(const QString &login);
	void denyInvitation(const QString &login);
private:
	Friend *me;
	FriendsList *friendsList;
	QHBoxLayout *statusLayout;
	QComboBox *statusCombo;
	QPushButton *addIcon;
	QPushButton *removeIcon;
	QVBoxLayout *mainLayout;
	QMap<int, ChatWindow*> chats;
	quint16 inactivityTime;

	QTimer* inactivity;
private slots:
	void statusChanged(int _index);
	void friendStatusChanged(Friend *_friend, QList<int> chats);
	void loadFriends(QList<Friend *> friends);

	void newMessageIncoming(Chat* chat, Friend* _friend, const QString& _text);
	void friendExit(Chat* chat, Friend* _friend);
	void chatTerminated(Chat* chat);
	void newChatWindow(Chat* chat);
	void newFriendChat(Chat* _chat, Friend* _friend);

	void inviteChatId(Chat* chat, QString login);
	void inviteFriend();	
	void removeFriend();	

	void friendInvitation(const QString &login);
	void friendAddition(Friend *_friend);
	void friendDenial(const QString &login);
	void friendRemoval(Friend *_friend, QList<int> chats);
	void awayInactivity();
	void restartInactivityCountdown();

};

}

#endif

